import {observable as o, computed as c, action as a} from 'mobx';
import _ from 'lodash';
import axios from 'core/axios';
import RootStore from 'core/Store.js';
import request from 'core/request.js';
import Im from 'immutable';
import {browserHistory} from 'react-router';

class Store extends RootStore {
    constructor(args) {
        super(args);
    }

    @o visible = false;
    @o type = '';
    @o text = '';
    @o timer = null;

    will() {

    }

    showMessage(type, text) {
        this.fire('message', {
            type: type === 1 ? $$.SEM.SUCCESS_TEXT : (type === 2 ? $$.SEM.ERROR_TEXT : $$.SEM.WARNING_TEXT),
            text: text
        });
    }


    mount() {
        this.on('message', (data) => {
            clearTimeout(this.timer);
            this.visible = true;
            this.type = data.type;
            this.text = data.type === $$.SEM.ERROR_TEXT && !data.text ? $$.LN.IS_ERROR_TRY_AGAIN : data.text;
            this.timer = setTimeout(() => {
                this.visible = false;
            }, data.duration || 3000);
        });
    }

}

export default Store;